<template>
    <div id="poster" >
        <el-form class="login-container" label-position="left" :rules="registerRules" label-width="0px" :model="registerForm">
            <h3 class="login_title">用户注册</h3>
            <el-form-item prop="username">
                <el-input type="text" v-model="registerForm.userName"  placeholder="账号"></el-input>
            </el-form-item>
            <el-form-item prop="realName">
                <el-input type="text" v-model="registerForm.realName"  placeholder="昵称"></el-input>
            </el-form-item>
            <el-form-item prop="phoneNumber">
                <el-input type="text" v-model="registerForm.phoneNumber"  placeholder="电话"></el-input>
            </el-form-item>

            <el-form-item prop="password">
                <el-input type="password" v-model="registerForm.password"  placeholder="密码"></el-input>
            </el-form-item>

            <el-form-item style="width: 100%">
                <el-button type="primary" style="width: 100%;background: #505458;border: none" v-on:click="register">注册</el-button>
            </el-form-item>
            <el-form-item style="width: 100%">
           <span id="tips"> 已有账户?前往
            <router-link to="/" style="text-decoration: none;" >登录</router-link> 界面</span>
            </el-form-item>

        </el-form>

    </div>
</template>


<script>
    import * as register from '../api/register'
    export default {
        name: "register",
        data() {
            return {
                registerForm: {
                    userName: '',
                    realName: '',
                    password: '',
                    phoneNumber:''
                },
                registerRules: {
                    userName: [
                        { required: true, trigger: "blur", message: "请输入您的账号" }
                    ],
                    realName: [
                        { required: true, trigger: "blur", message: "请输入您的昵称" }
                    ],
                    password: [
                        { required: true, trigger: "blur", message: "请输入您的密码" }
                    ],
                    phoneNumber: [
                        { required: true, trigger: "blur", message: "请输入您的电话" }
                    ]
                },
            }
        },
        methods: {
            register() {
                const that =this
                if(this.registerForm.userName===""||this.registerForm.password===""||this.registerForm.realName===""||this.registerForm.phoneNumber===""){
                    this.$message({
                        message: '请填写全部',
                        type: 'error'
                    })
                }
                else {
                    register.register(this.registerForm.userName,this.registerForm.realName,this.registerForm.phoneNumber,this.registerForm.password).then(function (response) {
                      if(response.data.msg==="用户名存在"){
                          that.$message({
                              message: '用户名存在',
                              type: 'error'
                          })
                      }
                      else if(response.data.msg==="成功") {
                          that.$message({
                              message: '注册成功',
                              type: 'success'
                          })
                          that.$router.push("/")
                      }
                    })
                }
            },
        }
    }
</script>

<style scoped>
    #poster {
        background:url("../assets/img/register-background.jpg") no-repeat;
        background-position: center;
        height: 100%;
        width: 100%;
        background-size: cover;
        position: fixed;
    }
    body{
        margin: 0px;
        padding: 0;
        overflow-y: hidden;
    }

    .login-container {
        border-radius: 15px;
        background-clip: padding-box;
        margin: 90px auto;
        width: 350px;
        padding: 35px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;
        position: absolute;
        left: 58em;
        top: 4em;
    }
    #tips{
        position: relative;
        left: 2.7em;
        font-size: 17px;
    }
    .login_title {
        margin: 0px auto 40px auto;
        text-align: center;
        color: #505458;
    }
    ::-webkit-scrollbar {
        width: 0px;
        height: 0px;
    }
    ::-webkit-scrollbar-track-piece {
        background-color: rgba(0, 0, 0, 0.2);
        -webkit-border-radius: 6px;
    }

    ::-webkit-scrollbar-thumb:vertical {
        /*height: 2px;*/
        background-color: rgba(223, 239, 238, 0.7);
        -webkit-border-radius: 6px;
    }

    ::-webkit-scrollbar-thumb:horizontal {
        width: 0px;
        background-color: rgba(223, 239, 238, 0.7);
        -webkit-border-radius: 2px;
    }


</style>
